package com.red.wood.module.system.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.red.wood.module.system.dao.ProvinceDao;

@Repository
public class ProvinceDaoImpl implements ProvinceDao{

	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	public List<Map<String, Object>> getList(){
		StringBuffer sql = new StringBuffer();
		sql.append("select id as id, provinceid as provinceid, province as province from provinces");
		return jdbcTemplate.queryForList(sql.toString());
		
	}
	
	public Map<String, Object> getByProvince(String province){
		StringBuffer sql = new StringBuffer();
		sql.append("select id as id, provinceid as provinceid, province as province from provinces where province = "+ "'" + province + "'");
		List<Map<String,Object>> list = jdbcTemplate.queryForList(sql.toString());
		if(null != list && !list.isEmpty()){
			return list.get(0);
		}
		return null;
	}
}
